package org.imagiccode.core.aspect;


import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 选择数据源切面类
 *
 * @author 134760685@qq.com
 * @create 2016-11-30 21:24
 **/
public class ChooseDataSource extends AbstractRoutingDataSource {
    public static Map<String, List<String>> METHODTYPE = new HashMap<>();

    protected Object determineCurrentLookupKey() {
        return HandleDataSource.getDataSource();
    }

    public void setMethodType(Map<String, String> map) {
        for (String key : map.keySet()) {
            List<String> v = new ArrayList<>();
            String[] types = map.get(key).split(",");
            for (String type : types) {
                if (StringUtils.isNotBlank(type)) {
                    v.add(type);
                }
            }
            METHODTYPE.put(key, v);
        }
    }
}
